package com.work.game.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.work.game.R;
import com.work.game.volley.BaseActivity;

public class CommonActivity extends BaseActivity {
    String title;
    String fragmentClass;

    public static void startActivity(Activity activity,String title,Class fragment){
        Intent intent = new Intent(activity, CommonActivity.class);
        intent.putExtra("title",title);
        intent.putExtra("fragmentClass",fragment.getCanonicalName());
        activity.startActivity(intent);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common);
        title=getIntent().getStringExtra("title");
        fragmentClass=getIntent().getStringExtra("fragmentClass");
        TextView titleView=findViewById(R.id.layout_top).findViewById(R.id.tv_actionbar_title);
        titleView.setText(title);
        Fragment instance = getInstance();
        if (instance != null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.layoutContain,instance)
                    .commit();
        }
        findViewById(R.id.layout_top).findViewById(R.id.lay_actionbar_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }


    public Fragment getInstance(){
        try {
            Class aClass = Class.forName(fragmentClass);
            Fragment fragment = (Fragment) aClass.newInstance();
            return  fragment;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
